﻿using Microsoft.Extensions.DependencyInjection;
using MyTestNameSpace;
using NLog.Extensions.Logging;


namespace NlogTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ServiceCollection services = new ServiceCollection();

            services.AddLogging(logBuilder =>
            {
                //要使用Nlog：
                //1：安装NLog.Extensions.Logging包
                //2：项目根目录下建nlog.config（日志配置文件）
                //3：using NLog.Extensions.Logging;
                //4：logBuilder.AddNLog();

                //本项目的日志配置文件指示日志保存到程序的根目录中
                logBuilder.AddNLog();
            }
            );

            services.AddScoped<Log>();
            services.AddScoped<Log2>();

            using (var sp = services.BuildServiceProvider())
            {
                var log = sp.GetService<Log>();
                var log2 = sp.GetService<Log2>();
                for ( int i = 0; i < 100000; i++ )
                {
                    log.LogPrint();
                    log2.LogPrint();
                }
                
            }
        }
    }
}
